package com.example.demo.packageTest;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

public class MyMessageDecoder extends ReplayingDecoder<Void> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> list) throws Exception {
        int length = byteBuf.readInt();
        byte[] content = new byte[length];
        byteBuf.readBytes(content); //把数据填充到content

        //封装成
        MessageProtocol protocol = new MessageProtocol();
        protocol.setLen(length);
        protocol.setContent(content);
        list.add(protocol);
    }
}
